<#import "commons.ftl" as m/>

package <@m.getBasePackage param=context flag=true/><@m.getServicePackage param=context flag=true/>impl;

import <@m.getBasePackage param=context flag=true/><@m.getDalPackage param=context flag=true/>${table.upperName}<@m.getDaoSuffix param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getModelPackage param=context flag=true/>${table.upperName}<@m.getModelSuffix param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getQueryPackage param=context flag=true/>${table.upperName}<@m.getQuerySuffix param=context/>;
import <@m.getBasePackage param=context flag=true/><@m.getServicePackage param=context flag=true/><@m.getServicePrefix param=context/>${table.upperName}<@m.getServiceSuffix param=context/>;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <pre>
 *  ${(table.comment)!''}默认业务实现类,建议流程控制/业务流程在API实现.
 *	如果需要项目内复用的业务代码,可以考虑在该层实现.
 *  不在统一实现事务配置,需要业务请在下面接口注解,需要注意,事务是整个类代理,所以请在public 入口方法注解.
 * </pre>
 *
 * @author ${context.conf.author!'系统生成'}
 * @email ${context.conf.email!'系统生成'}
 * @version ${context.conf.version!'1.0.0'}
 * @date ${.now?string('yyyy-MM-dd')}
 * @copyright ${context.conf.copyright!'系统生成'}
 */
@AllArgsConstructor
@Service("${table.lowerName}<@m.getServiceSuffix param=context/>")
public class <@m.getServiceImplPrefix param=context/>${table.upperName}<@m.getServiceImplSuffix param=context/> implements <@m.getServicePrefix param=context/>${table.upperName}<@m.getServiceSuffix param=context/> {
    /**
     * ${(table.comment)!''}持久操作对象
     */
    private final ${table.upperName}<@m.getDaoSuffix param=context/> ${table.lowerName}<@m.getDaoSuffix param=context/>;

    @Override
	public List<${table.upperName}<@m.getModelSuffix param=context/>> queryPage(${table.upperName}<@m.getQuerySuffix param=context/> query) {
		int count = ${table.lowerName}<@m.getDaoSuffix param=context/>.countPage(query);
		query.setTotalItem(count);
		if (count == 0) {
			return Collections.emptyList();
		} else {
			return ${table.lowerName}<@m.getDaoSuffix param=context/>.queryPage(query);
		}
	}

	@Override
	public ${table.upperName}<@m.getModelSuffix param=context/> queryById(${table.pkType!'Long'} ${table.lowerName}Id) {
		return ${table.lowerName}<@m.getDaoSuffix param=context/>.queryById(${table.lowerName}Id);
	}

	@Override
	public ${table.pkType!'Long'} insert${table.upperName}(${table.upperName}<@m.getModelSuffix param=context/> ${table.lowerName}) {
		${table.lowerName}<@m.getDaoSuffix param=context/>.insert${table.upperName}(${table.lowerName});
		return ${table.lowerName}.get${table.pkName!'Long'}();
	}

	@Override
	public int update${table.upperName}(${table.upperName}<@m.getModelSuffix param=context/> ${table.lowerName}) {
		return ${table.lowerName}<@m.getDaoSuffix param=context/>.update${table.upperName}(${table.lowerName});
	}

	@Override
	public int deleteById(${table.pkType!'Long'} ${table.lowerName}Id) {
		return ${table.lowerName}<@m.getDaoSuffix param=context/>.deleteById(${table.lowerName}Id);
	}

}
